﻿using lights.polytool.editor;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity.VisualScripting;
using UnityEditor;
using UnityEngine;
namespace lights.polytool.editor
{
    [CustomEditor(typeof(comp_quickmesh_elem))]
    internal class inspector_quickmesh_elem : Editor
    {
        public override void OnInspectorGUI()
        {


            base.OnInspectorGUI();
            var _target = this.target as comp_quickmesh_elem;
            if (_target == null)
            {
                return;
            }


            GUITool.ColorLabel("QuickMesh ELEM.", 24, Color.red);

            GUILayout.BeginHorizontal();

            if (_target.GetComponent<comp_polymesh>() == null)
            {
                GUILayout.Label("this is a normal mesh,if you want edit it.convert it.");
                if (GUILayout.Button("Convert to PolyMesh"))
                {
                    if (EditorUtility.DisplayDialog("warngin", "this will lost your mesh,ok?", "go", "cancel"))
                    {
                        var poly = _target.AddComponent<comp_polymesh>();
                        poly.InitQuad();
                    }
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            var colors = _target.GetRoot()._colors;
            for (var i = 0; i < 4; i++)
            {
                var _cindex = i;
                if (GUITool.BackColorButton("color" + i, colors[i]))
                {
                    _target._colorindex = _cindex;
                    _target.InitColor();
                }
            }
            GUILayout.EndHorizontal();


            inspector_quickmesh.CreateGUI(_target.transform);

        }
        void OnSceneGUI()
        {
            var _target = this.target as comp_quickmesh_elem;
            GizmoTool.DrawGizmoElem(_target, true, true);
            //GizmoTool.DrawGUIElem(_target);
        }

    }
}